package com.trippartner.client.menu.view;

import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.trippartner.client.menu.presenter.GlobalMenuPresenter;
import com.trippartner.client.pattern.HasCommand;

public class GlobalMenuView extends Composite implements GlobalMenuPresenter.Display {

	private final MenuBar globalMenu;
	private final MyMenuItem loadMenuFileItem;
	private final MyMenuItem saveMenuFileItem;
	private final MyMenuItem quitMenuFileItem;

	private final MyMenuItem addGeoPointMenuMapItem;
	private final MyMenuItem delCurrentPointMenuMapItem;
	private final MyMenuItem delAllPointsMenuMapItem;

	private final MyMenuItem helpMenuHelpItem;

	public GlobalMenuView() {
		super();

		// Create a menu bar
		globalMenu = new MenuBar();
		globalMenu.setAutoOpen(false);
		globalMenu.setAnimationEnabled(false);

		MenuBar fileMenu = new MenuBar(true);
		fileMenu.setAnimationEnabled(false);
		globalMenu.addItem(new MenuItem("Fichier", fileMenu));

		fileMenu.addItem(loadMenuFileItem = new MyMenuItem("Charger", getDummyCommand()));
		fileMenu.addItem(saveMenuFileItem = new MyMenuItem("Sauvegarder", getDummyCommand()));
		fileMenu.addItem(quitMenuFileItem = new MyMenuItem("Quitter", getDummyCommand()));

		MenuBar mapMenu = new MenuBar(true);
		globalMenu.addItem(new MenuItem("Carte", mapMenu));

		mapMenu.addItem(addGeoPointMenuMapItem = new MyMenuItem("Ajouter un point par ses coordonnées", getDummyCommand()));
		mapMenu.addItem(delCurrentPointMenuMapItem = new MyMenuItem("Supprimer le point courant", getDummyCommand()));
		mapMenu.addItem(delAllPointsMenuMapItem = new MyMenuItem("Supprimer tous les points", getDummyCommand()));

		// Create the help menu
		MenuBar helpMenu = new MenuBar(true);
		globalMenu.addSeparator();
		globalMenu.addItem(new MenuItem("Aide", helpMenu));

		helpMenu.addItem(helpMenuHelpItem = new MyMenuItem("Aide en ligne", getDummyCommand()));

		initWidget(globalMenu);
	}

	private Command getDummyCommand() {
		return new Command() {
			public void execute() {
				//afin de respecter le mvp, on ne fait pas l'action ici.
			}
		};
	}

	public HasCommand getLoadMenuFileItem() {
		return loadMenuFileItem;
	}

	public HasCommand getSaveMenuFileItem() {
		return saveMenuFileItem;
	}

	public HasCommand getQuitMenuFileItem() {
		return quitMenuFileItem;
	}

	public HasCommand getAddGeoPointMenuMapItem() {
		return addGeoPointMenuMapItem;
	}

	public HasCommand getDelCurrentPointMenuMapItem() {
		return delCurrentPointMenuMapItem;
	}

	public HasCommand getDelAllPointsMenuMapItem() {
		return delAllPointsMenuMapItem;
	}

	public HasCommand getHelpMenuHelpItem() {
		return helpMenuHelpItem;
	}

	public void setWidth(String width){
		setWidth(width);
	}

}
